<script type="text/x-red" data-template-name="http in">
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
        <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
    </div>
    <div class="form-row">
        <label for="node-input-serverId"><i class="fa fa-globe"></i> <span
                data-i18n="mqtt.label.broker"></span></label>
        <!--        <input type="text" id="node-input-broker">-->
        <select id="node-input-serverId" style="width:70%;">
        </select>

    </div>
    <div class="form-row">
        <label for="node-input-method"><i class="fa fa-tasks"></i> <span data-i18n="httpin.label.method"></span></label>
        <select type="text" id="node-input-method" style="width:70%;">
            <option value="get">GET</option>
            <option value="post">POST</option>
            <option value="put">PUT</option>
            <option value="delete">DELETE</option>
            <option value="patch">PATCH</option>
        </select>
    </div>
    <div class="form-row form-row-http-in-upload hide">
        <label>&nbsp;</label>
        <input type="checkbox" id="node-input-upload" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-upload" style="width: 70%;" data-i18n="httpin.label.upload"></label>
    </div>
    <div class="form-row">
        <label for="node-input-url"><i class="fa fa-globe"></i> <span data-i18n="httpin.label.url"></span></label>
        <input id="node-input-url" type="text" placeholder="/url">
    </div>

<!--    <div class="form-row row-swagger-doc">-->
<!--        <label for="node-input-swaggerDoc"><i class="fa fa-file-text-o"></i> <span data-i18n="httpin.label.doc"></span></label>-->
<!--        <input type="text" id="node-input-swaggerDoc">-->
<!--    </div>-->
<!--    <div id="node-input-tip" class="form-tips"><span data-i18n="httpin.tip.in"></span><code><span-->
<!--            id="node-input-path"></span></code>.-->
<!--    </div>-->
</script>

<script type="text/javascript">
    (function () {
        RED.nodes.registerType('http in', {
            category: 'network',
            name: "监听HTTP",
            color: "rgb(231, 231, 174)",
            defaults: {
                name: {value: ""},
                url: {value: "", required: true},
                method: {value: "get", required: true},
                serverId: {value: "", required: true},
                upload: {value: false}
                // swaggerDoc: {type: "swagger-doc", required: false}
            },
            inputs: 0,
            outputs: 1,
            icon: "white-globe.svg",
            label: function () {
                if (this.name) {
                    return this.name;
                } else if (this.url) {
                    var root = RED.settings.httpNodeRoot;
                    if (root.slice(-1) != "/") {
                        root = root + "/";
                    }
                    if (this.url.charAt(0) == "/") {
                        root += this.url.slice(1);
                    } else {
                        root += this.url;
                    }
                    return "[" + this.method + "] " + root;
                } else {
                    return "监听HTTP";
                }
            },
            labelStyle: function () {
                return this.name ? "node_label_italic" : "";
            },
            oneditprepare: function () {

                var me = this;
                $.ajax({
                    url: RED.settings.apiBaseUrl + "/network/config/_query/no-paging?paging=false&where=type=HTTP_SERVER"
                }).then(function (res) {
                    if (res.result) {
                        $(res.result).each(function () {
                            $("#node-input-serverId").append($("<option>").val(this.id).text(this.name))
                        })
                    }
                    $("#node-input-serverId").val(me.serverId);
                })


            }

        });
    })();
</script>
